explorer.TextEditor = function(){};
core.extendClass('explorer.TextEditor', 'core.JSFrame');

explorer.TextEditor.prototype.loadContents = function(){
    var instance = this;
    this.saveButton = new core.form.Button({
        text: 'Save',
        handler: function(){
            instance.sendMessage('saveTextFile', instance.frame.body.getValue(), function(data){
            }, function(code, error){
                instance.application.showError(error);
            }, instance.textEditor);
        }
    });
    var toolbar = new core.Tabs({
        toolbar: true,
        cls: 'toolbar'
    });
    toolbar.addTab(this.saveButton);
    this.frame.addToolbar(toolbar);

    this.nameEditor = new core.form.TextField({
        id: 'name'
    });
    this.textEditor = new core.form.TextArea({
        id: 'text',
        cls: 'fixed-font'
    });
    this.nameLbl = new core.Label({
        text: 'File name:',
        align: 'left'
    });
    this.textLbl = new core.Label({
        text: 'File contents:',
        align: 'left'
    });
    this.frame.body.timeout = 10000;
    this.frame.body.on('change_by_timeout', function(){
        instance.sendMessage('updateData', instance.frame.body.getValue());
    });
    this.setContent([this.nameLbl, this.nameEditor, this.textLbl, this.textEditor], '1', 'd, d, d, 1');
    this.sendMessage('getData', {}, function(data){
        instance.frame.body.setValue(data);
    }, null, this.textEditor);
};

explorer.TextViewer = function(){};
core.extendClass('explorer.TextViewer', 'core.HTMLPanel');

explorer.TextViewer.prototype.init = function(config){
//    config.bottom = true;
    config.cls = 'fixed-font';
    this.superCall('init', arguments, config);
    if(config.data){
        this.setHTML(core.escapeHTML(config.data.text));
    }
};

explorer.ApplicationLinkViewer = function(){};

core.extendClass('explorer.ApplicationLinkViewer', 'core.Box');

explorer.ApplicationLinkViewer.prototype.init = function(config){
    var instance = this;
    this.nameLbl = new core.Label({
        text: config.data.name+', version: '+config.data.version,
        align: 'left'
    });
    this.descriptionLbl = new core.Label({
        text: 'Description: '+config.data.description,
        align: 'left'
    });
    this.callBtn = new core.form.Button({
        text: 'Start',
        handler: function(){
            config.frame.sendMessageToViewer({});
        }
    });
    this.superCall('init', arguments, {
        items:[this.callBtn, this.nameLbl, this.descriptionLbl],
        columns: '1', rows: 'd, d, 1'
    });
};
